import java.util.Arrays;
import java.util.Scanner;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @description: 合并两个数组
 * @author: WangBlue
 * @create: 2023-10-28 17:21
 **/
public class MergeArray {
    public static void main(String[] args) {
        System.out.println("输入生成数组的长度分别为: ");
        int arrayLength1 = new Scanner(System.in).nextInt();
        int arrayLength2 = new Scanner(System.in).nextInt();
        // 分别生成两个数组
        int[] array = getArray(arrayLength1);
        int[] array1 = getArray(arrayLength2);
        // 将两个数组进行合并操作
        int[] result  = mergeArray(array, array1);
        Arrays.sort(result);
        System.out.println("合并并排序之后的数组为：" + Arrays.toString(result));

    }

    /**
     *
     * @param arrayLength 输入数组的长度
     * @return 返回生成好的数组
     */
    public static int [] getArray(int arrayLength){

        int[] ints = new int[arrayLength];
        for (int i = 0; i < ints.length; i++) {
            ints[i] = ThreadLocalRandom.current().nextInt(100);
        }
        return ints;
    }

    /**
     * 合并两个数组
     * @param a 数组a
     * @param b 数组b
     * @return 合并之后的数组
     */
    public static int[] mergeArray(int [] a, int [] b) {
        int[] result = new int[a.length + b.length];
        System.arraycopy(a,0,result,0, a.length);
        System.arraycopy(b, 0, result, a.length, b.length);
        return result;
    }


}
